import logging
import allure
from utils.database import Database
import requests
from config.config import *

@allure.step("2.发送HTTP请求")
def send_http_request(**request_data):
    res = requests.request(**request_data)
    response = {
        "status_code": res.status_code,
        "json_data": res.json(),
        "response_time": res.elapsed.total_seconds() * 1000
    }

    #写入慢接口
    from utils.slow_api_write_csv import ApiLogger
    ApiLogger().log_request(res.url,request_data["method"],request_data["params"],request_data["data"],request_data["json"],response_time=response["response_time"])
    logging.info(f"2.发送HTTP请求，响应内容为: {response}")
    print(response)
    return response

def send_jdbc_request(sql):
    return Database().get_one(sql)